$(function () {
   
    
    $('.item').find('a').each(function() {
		$(this).attr("href" , "/quick-view/?idproduto=" + $(this).attr("rel") + "?KeepThis=true&TB_iframe=true&width=220&height=225");
	});
	
	$('.item .anchor').click(function () {
		$(this).parent().find('a').trigger('click');
	});
	
	$('.item a').click(function(e) {
		
		//e.preventDefault();
		
	});
	
	$('#lookwrapper .controls .buy .buybutton').click(function(e) {
		
		//e.preventDefault();
		
	});
	
	
	// When The anchor has hovered.
	$('item').mouseenter(function() {
		$(this).find('.name').fadeIn('fast');
	});
	//When The Item anchor has leaved.
	$('item').mouseleave(function() {
		$(this).find('.name').delay(300).hide();
	});
	
	// When The buy button has hovered.
	$('.buy').mouseenter(function() {
		$(this).find('.information').fadeIn('fast');
	});
	//When The Item buy button has leaved.
	$('.buy').mouseleave(function() {
		$(this).find('.information').delay(300).hide();
	});
    

		
	$('#departament-navigation ul li a, #departament-navigation h4, #leftside .refino label, #leftside #category-navigation .search-single-navigator ul:first').each(function () {
		var oldString = $(this).html();
		var newString = oldString.replace(/\([0-9]+\)/, "");
		$(this).html(newString);
	});
	
    
    $("#departament-rightbar .main .vitrine .prateleira").find("ul").each(function(){
		var originalText = $(this).find("li a span.produto-nome").text();

		if(originalText.length > 30){
			var shortText = originalText.substr(0, 30);
			if(shortText.charAt(30) != " "){
				shortText = shortText.substr(0, shortText.lastIndexOf(" "));
			}
			$(this).find("li a span.produto-nome").text(shortText + " ...");
		}
	});
    
    
    // Departamentos
	Cufon.replace('#departament-navigation h4', {
        fontFamily: 'Proxima Nova Rg'
    });
	Cufon.replace('#departament-navigation h4 a', {
        fontFamily: 'Proxima Nova Rg'
    });
	Cufon.replace('#departament-navigation h5', {
        fontFamily: 'Proxima Nova Rg'
    });
	Cufon.replace('#departament-navigation h5 a', {
        fontFamily: 'Proxima Nova Rg'
    });
	Cufon.replace('#departament-rightbar .prateleira li a span', {
        fontFamily: 'Proxima Nova Rg'
    });
	Cufon.replace('#lookwrapper .items .item .name', {
        fontFamily: 'Proxima Nova Rg'
    });
    
});